﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace DLL.Entities
{
    public class Utility
    {
        public static bool DeleteFile(string fileToDelete)
        {
            try
            {
                if (File.Exists(fileToDelete))
                {
                    File.Delete(fileToDelete);
                    return true;
                }
                else
                    return true;
            }
            catch (Exception ex)
            {
                // Log the exception
                Utility.LogFile(ex.ToString());
                return false;
            }
      
        }

        public static void LogFile(string strLogText)
        {
            StreamWriter log;

            if (!File.Exists("../../../MIS/XML/logfile.txt"))
            {
                log = new StreamWriter("../../../MIS/XML/logfile.txt");
            }
            else
            {
                log = File.AppendText("../../../MIS/XML/logfile.txt");
            }

            // Write to the file:
            log.WriteLine(DateTime.Now);
            log.WriteLine(strLogText);
            log.WriteLine();

            // Close the stream:
            log.Close();

        }

        public static bool CopyFile(string fileToCopy, String pathname)
        {
            try
            {
                if (File.Exists(pathname + fileToCopy))
                {
                    string filename = pathname + DateTime.Now.ToFileTime() + "_" + fileToCopy;
                    File.Copy(pathname + fileToCopy, filename, true);
                    return true;
                }
                else
                    return true;
            }
            catch (Exception ex)
            {
                // Log the exception
                Utility.LogFile(ex.ToString());
                return false;
            }

        }

        

    }
    
}
